home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Converters / Convert_PICT / Source / CommentedPSCode / Common < prev    next >
Text File  |  1995-06-12  |  7KB  |  347 lines

  1. /COPYING_INFO
  2. (
  3.     Created by Convert PICT a PICT to eps converter.
  4.     Copyright (C) 1993 David John Burrowes
  5.     The following PS routines are distributed under terms of GNU General Public License. 
  6.     See any copy of the GPL for more info. E.g. in COPYING in Convert PICT's online help.
  7. )
  8. def
  9.  
  10. %BEGIN Common
  11. %
  12. %    Pen size 
  13. %
  14. /penWidth 1 def
  15. /penHeight 1 def
  16.  
  17. %
  18. %    The coordinates of the last rectangle used
  19. %
  20. /lastTop 0 def
  21. /lastLeft 0 def
  22. /lastBottom 0 def
  23. /lastRight 0 def
  24. %
  25. %    Define color values
  26. %
  27. /foregroundColor [0 0 0] def
  28. /backgroundColor [1 1 1] def
  29. %
  30. %    Define the three patterns used
  31. %
  32. /backPattern 20 dict def
  33. backPattern begin
  34.     /QDPatType 0 def
  35.     /QDPatData <FFFFFFFFFFFFFFFF>  def    % white
  36.     /QDPatGrey    1 def
  37. end
  38. /penPattern 20 dict def
  39. penPattern begin
  40.     /QDPatType 0 def
  41.     /QDPatData <0000000000000000>  def
  42.     /QDPatGrey    0 def
  43. end
  44. /fillPattern 20 dict def
  45. fillPattern begin
  46.     /QDPatType 0 def
  47.     /QDPatData <0000000000000000>  def    % black
  48.     /QDPatGrey    1 def
  49. end
  50. %
  51. %    set the drawing mode
  52. %
  53. /patternMode    /patCopy    def
  54. %
  55. %    Calculate the PostScript level currently in use.
  56. %
  57. /PSlevel
  58.     systemdict /languagelevel known
  59.         {languagelevel}
  60.         {1}
  61.     ifelse
  62. def
  63.  
  64.  
  65.  
  66. %%%%%%%%%%%%%
  67. %    Name:    usePattern
  68. %    Syntax:    pattern    usePattern    -
  69. %    About:    Set the current drawing patten to the one passed.
  70. %            Note: We do some weird double-use of dictionary in PS 2 code
  71. %%%%%%%%%%%%%
  72. /usePattern
  73. {
  74.     /QDPatternDict exch def
  75.     /patternType QDPatternDict /QDPatType get def
  76.  
  77.     patternType 2 eq
  78.     { QDPatternDict /QDColorValue  get  useColor }
  79.     {
  80.         PSlevel 1 eq
  81.         {
  82.             %
  83.             %    Can't do true patterns, so compute percent gray, and weight by
  84.             %    appropriate ammounts of fore and back colors.
  85.             %
  86.             /patGrey  QDPatternDict /QDPatGrey get  def
  87.             /invGrey 1 patGrey sub def
  88.             0 1 2
  89.             {
  90.                 /index exch def
  91.                 foregroundColor index get invGrey mul
  92.                     backgroundColor index get patGrey mul add
  93.             }
  94.             for
  95.             setrgbcolor
  96.         }
  97.         {
  98.             % PS level 2
  99.             patternType 0 eq
  100.             {
  101.                 /PSPatDict 15 dict def
  102.                 PSPatDict begin
  103.                     /PaintType    1    def
  104.                     /PatternType    1    def
  105.                     /TilingType    1    def
  106.                     /BBox        [0 0 8 8]    def
  107.                     /XStep        8    def
  108.                     /YStep        8    def
  109.                     /myData    QDPatternDict /QDPatData get def
  110.                     /PaintProc    {
  111.                                 %
  112.                                 %    Draw foreground bits, and then draw background
  113.                                 %    bits, using different colors depending on mode.
  114.                                 %
  115.                                 begin
  116.                                     patternMode /patBic eq
  117.                                     patternMode /notPatCopy eq
  118.                                     or
  119.                                         { 0 1 2 { backgroundColor exch get } for }
  120.                                         %patOr, patCopy, and default
  121.                                         { 0 1 2 { foregroundColor exch get } for }
  122.                                     ifelse
  123.                                     setrgbcolor
  124.                                     8 8 false
  125.                                     [1 0 0  1 0 0] 
  126.                                     myData
  127.                                     imagemask
  128.  
  129.                                     patternMode /notPatOr eq
  130.                                     patternMode /notPatCopy eq
  131.                                     or
  132.                                         { 0 1 2 { foregroundColor exch get } for }
  133.                                         % patCopy, notBic and default
  134.                                         { 0 1 2 { backgroundColor exch get } for }
  135.                                     ifelse
  136.                                     setrgbcolor
  137.                                     8 8 true
  138.                                     [1 0 0  1 0 0] 
  139.                                     myData
  140.                                     imagemask
  141.                                 end
  142.                                 } def 
  143.                 end
  144.                 PSPatDict matrix makepattern setpattern
  145.             }
  146.             {
  147.                 % Pat type 2
  148.                 /PSPatDict 20 dict def
  149.                 PSPatDict begin
  150.                     /PaintType    1    def
  151.                     /PatternType    1    def
  152.                     /TilingType    1    def
  153.                     /BBox        [0 0 QDPatternDict  /QDDestWidth  get
  154.                                     QDPatternDict  /QDDestHeight get] def
  155.                     /XStep        QDPatternDict  /QDDestWidth  get def
  156.                     /YStep        QDPatternDict  /QDDestHeight get def
  157.  
  158.                     /ImageType    1    def
  159.                     /Width        QDPatternDict  /Width get def
  160.                     /Height        QDPatternDict  /Height get def
  161.                     /BitsPerComponent
  162.                                 QDPatternDict  /BitsPerComponent get  def
  163.                     /Decode            [ 0 2 BitsPerComponent exp 1 sub ] def
  164.                     /ImageMatrix    [1 0 0  1 0  0]  def
  165.                     /DataSource     QDPatternDict  /QDPatBitmap get def
  166.                     /PaintProc    {
  167.                                     /ourDict exch def 
  168.                                     [/Indexed /DeviceRGB
  169.                                         QDPatternDict  /QDNumColors get
  170.                                         QDPatternDict  /QDColorTable get]
  171.                                     setcolorspace
  172.                                     ourDict  image
  173.                                 } def 
  174.                 end
  175.                 PSPatDict matrix makepattern setpattern
  176.             }
  177.             ifelse
  178.         }
  179.         ifelse
  180.     }
  181.     ifelse
  182. }
  183. def
  184.  
  185.  
  186.  
  187. %%%%%%%%%%%%%
  188. %    Name:    useColor
  189. %    Syntax:    [red green blue] useColor -
  190. %    About:    Given array with R G B values, set the current color to it.
  191. %%%%%%%%%%%%%
  192. /useColor
  193. {
  194.     /colorArray exch def
  195.     colorArray 0 get
  196.     colorArray 1 get
  197.     colorArray 2 get
  198.     setrgbcolor
  199. }
  200. def
  201.  
  202. %%%%%%%%%%%%%
  203. %    Name:    setupForArcPath
  204. %    Syntax:    width height bottom left setupForArcPath  xcoord ycoord radius
  205. %    About:    Given bounds of an oval defined by a rectangle, return its
  206. %            center in undistored space & it's radius (good for use with arc)
  207. %            Also, distort coord system so oval can be drawn (not as circle).
  208. %            If width is > height (computations merely mirrored if reversed)
  209. %            scale coord system, push x coord center, push y coord center as:
  210. %                (ovalBottom-(ovalHeight/2)) * (ovalWidth/ovalHeight)
  211. %            (Get center then unscale it)
  212. %%%%%%%%%%%%%
  213. /setupForArcPath
  214. {
  215.     /ovalLeft exch def
  216.     /ovalBottom exch  def
  217.     /ovalHeight exch  def
  218.     /ovalWidth exch  def
  219.     
  220.     ovalHeight 0 le
  221.     ovalWidth 0 le
  222.     or
  223.     { 0 0 0 }    % if height or with <= 0, return center 0,0 radius 0
  224.     {
  225.         ovalWidth ovalHeight gt
  226.         {
  227.             1 ovalHeight ovalWidth div scale
  228.             ovalLeft ovalWidth 2 div add    % X coordinate center
  229.             ovalBottom ovalHeight 2 div  sub ovalWidth ovalHeight div mul
  230.             ovalWidth 2 div                    % radius
  231.         }
  232.         {
  233.             ovalWidth ovalHeight div 1 scale
  234.             ovalLeft ovalWidth 2 div  add   ovalHeight ovalWidth div   mul
  235.             ovalBottom ovalHeight 2 div sub    % Y coord center
  236.             ovalHeight 2 div                % radius
  237.         }
  238.         ifelse
  239.     }
  240.     ifelse
  241. }
  242. def
  243.  
  244. %%%%%%%%%%%%%
  245. %    Name:    regionBounds
  246. %    Syntax:    top left bottom right regionBounds -
  247. %    About:    Build a closed path given the coordinates on the stack.
  248. %%%%%%%%%%%%%
  249. /regionBounds
  250. {
  251.     /right    exch def
  252.     /bottom    exch def
  253.     /left        exch def
  254.     /top        exch def
  255.  
  256.     newpath
  257.         left top moveto
  258.         right top lineto
  259.         right bottom lineto
  260.         left bottom lineto
  261.     closepath
  262. }
  263. def
  264.  
  265. %%%%%%%%%%%%%
  266. %    Name:    regionPath
  267. %    Syntax:    x y ... x y  n  regionPath -
  268. %    About:    Given N, and N pairs of x,y coords which define a region's edge,
  269. %            build a path through these coordinates.
  270. %%%%%%%%%%%%%
  271. /regionPath
  272. {
  273.     /numShapes exch def
  274.     newpath
  275.     numShapes
  276.     {
  277.         /numPoints exch def
  278.         /y exch def
  279.         /x exch def
  280.         x y moveto
  281.         numPoints 1 sub
  282.         {
  283.             /y exch def
  284.             /x exch def
  285.             x y lineto
  286.         }
  287.         repeat
  288.         closepath
  289.     }
  290.     repeat
  291. }
  292. def
  293.  
  294. %%%%%%%%%%%%%
  295. %    Name:    startPict
  296. %    Syntax:    num startPict -
  297. %    About:    Called before any converted pict data.  Do any setup here.
  298. %%%%%%%%%%%%%
  299. /startPict
  300.     {pop}
  301. def
  302.  
  303. %%%%%%%%%%%%%
  304. %    Name:    QDClip    [0001]
  305. %    Syntax:    regionInfo QDclip -
  306. %    About:    Sets the clipping path for the drawing. If shapes in region
  307. %            other than bounding rect, build their path and clip to them too.
  308. %%%%%%%%%%%%%
  309. /QDclip
  310. {
  311.     initclip
  312.     regionBounds
  313.     clip
  314.     /numShapes exch def
  315.     numShapes  0 gt
  316.     {
  317.         numShapes
  318.         regionPath
  319.         clip
  320.     }
  321.     if
  322. }
  323. def
  324.  
  325. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  326. %    Name:    endPict    [00FF]
  327. %    Syntax:    - endPict -
  328. %    About:    Marks the end of a picture.  Do any cleanup here.
  329. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  330. /endPict
  331.     {}
  332. def
  333.  
  334. %%%%%%%%%%%%%
  335. %    Name:    headerOp    [0C00]
  336. %    Syntax:    [num num num num num num] headerOp -
  337. %            [num num num num [rect] num] header op -
  338. %    About:    Two forms (former def. in IM V5, latter im V6. Args in same order listed there)
  339. %%%%%%%%%%%%%
  340. /headerOp
  341.     {pop}
  342. def
  343.  
  344.  
  345. %END Common
  346.  
  347.